﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using TrackSystem.Entities.Models;

namespace TrackSystem.EntityFramework.Mapping
{
    public class LoopMap : IEntityTypeConfiguration<LoopTable>
    {
        public void Configure(EntityTypeBuilder<LoopTable> builder)
        {
            builder.ToTable("Loop");

            builder.HasKey(s => s.Id);
            builder.HasIndex(s => s.Id).IsUnique();

            builder.Property(s => s.Name).HasMaxLength(50).IsRequired();
            builder.HasIndex(s => s.Name).IsUnique();

            builder.Property(s => s.Description).HasMaxLength(200);

            builder.HasOne(s => s.Equip)
                    .WithMany(e => e.Loops)
                    .HasForeignKey(s => s.equipId)
                    .OnDelete(DeleteBehavior.NoAction);
        }
    }
}
